import { Controller } from 'egg';
import { Prefix, All, Query, Body, Params, View } from 'dean-route-controller';
const prettier = require('prettier');

@Prefix('/test')
class Test extends Controller {
  @All('/api')
  @View('index')
  public async api() {
    const { ctx, service } = this;
    const time = new Date().getTime();
    const token =
      '744758c075836f5fad6f3411c07be4c74f7173585941d745635ed9446a831faa';
    await service.generatApi.init('http://192.168.2.222:3000', token, ctx);

    const { data: project } = await service.generatApi.getProjectInfo();
    const project_id = project._id;
    const { data: apiList } = await service.generatApi.getApiList({
      project_id,
      page: 1,
      limit: 9999,
    });
    const apis: Array<any> = apiList.list;
    const results: Array<any> = [];
    for (let api of apis) {
      const apiInfo = await service.generatApi.genApiById(api._id);
      results.push(apiInfo);
    }
    console.log(time, await ctx.zipCode.compactFolder(), this.app);

    return {
      code: prettier.format(JSON.stringify(results, null, 4), {}).trim(),
    };
  }
  /**
   * @param query url参数
   * @param body 请求体
   * @param params 请求参数
   * */
  @All('/test')
  public async test(
    @Query('test') query,
    @Body() body,
    @Params() params
  ): Promise<any> {
    console.log(query, body, params);
    return '';
  }
}
export default Test;
